<template>
    <div>
        <el-dialog title="详情" v-model="isShowDialog" width="600px" @close="closeDialog">
            <el-form :model="formModel" :disabled="true" size="default" label-width="120px">
                <el-form-item label="组名称" prop="groupName">
                    <el-input v-model="formModel.groupName" show-word-limit maxlength="30" placeholder=""
                        clearable></el-input>
                </el-form-item>
                <el-form-item label="执行类型" prop="executeType">
                    <el-select v-model="formModel.executeType" placeholder="">
                        <el-option v-for="item in DictInfo.groupExecuteType" :key="item.key" :label="item.label"
                            :value="item.key" />
                    </el-select>
                </el-form-item>
                <el-form-item v-if="formModel.executeType === 2" label="间隔时间(S)" prop="delaySeconds">
                    <el-input-number v-model="formModel.delaySeconds" show-word-limit :min="1" :max="999999" placeholder=""
                        clearable></el-input-number>
                </el-form-item>
                <el-form-item v-if="formModel.executeType === 1" label="cron表达式" prop="cron">
                    <el-input v-model="formModel.cron" show-word-limit maxlength="50" placeholder="" clearable></el-input>
                </el-form-item>
                <el-form-item label="执行状态" prop="executeStatus">
                    <el-select v-model="formModel.executeStatus" placeholder="">
                        <el-option v-for="item in DictInfo.groupExecuteStatus" :key="item.key" :label="item.label"
                            :value="item.key" />
                    </el-select>
                </el-form-item>
                <el-form-item label="执行IP" prop="executeIp">
                    <el-input v-model="formModel.executeIp" show-word-limit maxlength="30" placeholder=""
                        clearable></el-input>
                </el-form-item>
                <el-form-item label="执行批次号" prop="executeBatchNo">
                    <el-input v-model="formModel.executeBatchNo" show-word-limit maxlength="20" placeholder=""
                        clearable></el-input>
                </el-form-item>
                <el-form-item label="上次执行时间" prop="lastExecuteTime">
                    <el-input v-model="formModel.lastExecuteTime" show-word-limit maxlength="256" placeholder=""
                        clearable></el-input>
                </el-form-item>
                <el-form-item label="备注" prop="remark">
                    <el-input v-model="formModel.remark" show-word-limit maxlength="400" placeholder=""
                        clearable></el-input>
                </el-form-item>
            </el-form>
            <el-divider content-position="left">任务顺序</el-divider>
            <TaskRelation :data="formModel.taskList"></TaskRelation>
            <template #footer>
                <span class="dialog-footer">
                    <el-button @click="() => closeDialog()" size="default">关 闭</el-button>
                </span>
            </template>
        </el-dialog>
    </div>
</template>

<script lang="ts">
import { reactive, toRefs, defineComponent, inject } from 'vue';
import { TaskGroupInfoDetailModel } from '/@/interfaces/DataPipelineModel';
import useObjectUtil from '/@/utils/objectUtil';
import { DictInfo } from '/@/enums/dict-info-enum';
import TaskRelation from './task-relation.vue';

interface State {
    isShowDialog: boolean | true,
    submitLoading: boolean | false,
    formModel: TaskGroupInfoDetailModel,
}
export default defineComponent({
    name: 'TaskGroupInfoDetail',
    components: { TaskRelation },
    emits: ['onClose'],
    setup(props, context) {
        const state = reactive<State>({
            isShowDialog: true,
            submitLoading: false,
            formModel: {
                id: undefined,
                groupName: undefined,
                executeType: undefined,
                executeStatus: undefined,
                delaySeconds: undefined,
                cron: undefined,
                executeIp: undefined,
                executeBatchNo: undefined,
                lastExecuteTime: undefined,
                remark: undefined,
                taskList: [],
            },
        });
        const methodMap = reactive({
            // 关闭弹窗
            closeDialog: function () {
                state.isShowDialog = false;
                context.emit('onClose');
            }
        });
        // 表单赋值
        const detailData: TaskGroupInfoDetailModel | undefined = inject<TaskGroupInfoDetailModel>('detailData');
        if (undefined !== detailData) {
            useObjectUtil.copyProperties(detailData, state.formModel);
        } else {
            console.error("found undefined for detail");
        }
        return {
            DictInfo,
            ...toRefs(state),
            ...toRefs(methodMap),
        };
    },
});
</script>
